package com.aceitunaproject.shared.map;
/**
 * Map Object
 * 
 * @author Sven Berger
 * @email admin@svchb.net
 * 
 */
public class Map {

	//maximum size 65535 (unsigned short)
	private static char sizex;
	private static char sizey;
	private static boolean exists=false;
	private MapTile[] Nodes=null;
	
	private Map()
	{
	}
	/**
	 * @param x
	 * @param y
	 * @throws Exception
	 */
	public Map(char x,char y)throws Exception 
	{
		if(exists)throw new Exception();
		Map.sizex=x;
		Map.sizey=y;
		this.Nodes=new MapTile[Map.sizex*Map.sizey];
		exists=true;
	}
	/**
	 * Returns a hash that represents the index to the Map array
	 * 
	 * @param char xpos - the x-coordinate on the map
	 * @param char ypos - the y-coordinate on the map
	 * @return maptileid
	 */
	private static int hash(char xpos, char ypos)
	{
		int maptileid=0;
		if(sizey<10000)maptileid=xpos*10000+ypos;
		else maptileid=xpos*100000+ypos;
		return maptileid;
	}
	/**
	 * @param xpos
	 * @param ypos
	 * @return MapTile
	 */
	public MapTile get(char xpos, char ypos)
	{
		return(this.Nodes[Map.hash(xpos, ypos)]);
	}
	/**
	 * @param maptileid
	 * @return MapTile
	 */
	public MapTile get(int maptileid )
	{
		return(this.Nodes[maptileid]);
	}
	/*
	 * todo:
	public void loadMap()
	{
		//different server/client
	}
	public void render()
	{
		//only client
	}
	public void update()
	{
	}
	*/
	
	
}